<template>
	<view class="pageBody">
		<view class="pageHead">
			<view class="headStatus" :style="{height: sysHeight}"></view>
			<view class="headNav">
				<view class="iconfont icon-fanhui2" @tap="returns"></view>
				<view class="headTitle">
					<!-- 代理中心 -->
					ۋاكالەتچى مەركىزى
				</view>
			</view>
		</view>
		<view class="bodyWrap" :style="{height: 'calc(100vh - ' + headH + ')'}">
			<view class="cardBox">
				<view class="vipCard">
					<image class="avatar" :src="userInfo.avatar || '/static/images/f.png'" mode="aspectFill">
					<view class="cardInfo">
						<view class="infoTop">
							<view class="name">
								{{userInfo.nickname || 'ئىسمى'}}
							</view>
							<view class="vipUser" v-if="isVip">
								ۋاكالەتچى
							</view>
							<view class="ordinaryUser" v-else>
								ئاددىي ئەزا
							</view>
						</view>
						<view class="infoBtm">
							<view class="infoTime rtl" v-if="isVip">
								ۋاكالەتچى تۇشۇش ۋاقتى
								{{userInfo.agent_overdue_time}}
							</view>
							<view class="infoTime" v-else>
								تېخى ئاشمىدىڭىز
							</view>
						</view>
					</view>
				</view>
				<view class="btmImg"></view>
			</view>
			<view class="agentBox">
				<view class="agentTitle">
					<view class="titleIcon"></view>
					<view class="titleIcon"></view>
					<view class="title">ۋاكالەتچى پايدىسى</view>
					<view class="titleIcon"></view>
					<view class="titleIcon"></view>
				</view>
				<view class="contentBox">
					<view class="itemBox" v-for="(item, index) in listData">
						<view class="boxImg">
							<image class="boxIcon" :src="item.imgUrl" mode=""></image>
						</view>
						<view class="boxInfo">
							<view class="boxName">
								{{item.name}}
							</view>
							<view class="boxContent">
								{{item.info}}
							</view>
						</view>
					</view>
				</view>
				<view class="tips">
					<image src="/static/images/train-tuigai.png" mode=""></image>
					پايدا ئايرىلغان پۇل پۇل قاپچۇقىڭىزغا ئاپتۇماتىك كىردۇ ، نەقلەشتۈرسىڭىز شۇ ھامان ئۇرۇپ بىرىلدۇ
				</view>
			</view>
			<view class="btmBox">
				<view class="btmBoxWrap">
					<view class="programme">
						<view class="tips">ئىتىۋارلار</view>
						<view class="dayMoney">
							<text>كۈنلۈكى</text>
							<text>
								{{userInfo.money_day || 0}}
							</text>
							<text> يۈەن توختايدۇ</text>
						</view>
						<view class="yearMoney">¥ {{userInfo.money || 0}}</view>
						<view class="time">
							 <text>
								 يىل 
							 </text>
							 <text>
								{{userInfo.time || 2}}
							 </text>
							 <text>
								 ۋاكالەتچىلىك ۋاقتى
							 </text>
						 </view>
					</view>
					<view class="btmSub">
						<view class="money">
							¥ {{userInfo.money || 0}}
						</view>
						<view class="subBtn" @click="toPay">
							ۋاكالەتچى بۇلاي
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
	let headH= uni.getSystemInfoSync().statusBarHeight + 43 + 'px';
	import { userAgencyCenter, userOpenAgent, serOpenPayCancel, userOpenPayAgain } from '@/api/dailyLife.js';
	export default {
		data() {
			return {
				sysHeight: sysHeight,
				headH: headH,
				userInfo: {},
				listData: [
					{
						imgUrl: '/static/images/vipIcon1.png',
						name: 'بىر بىلەتتىن 25يۈەن ئايرىلدۇ',
						info: 'ئايرىپىلان بىلەت پايدىسى'
					},
					{
						imgUrl: '/static/images/vipIcon2.png',
						name: 'بىر بىلەتتىن 5 يۈەن ئايرىلدۇ ',
						info: 'پويىز بىلەت پايدىسى'
					},
					{
						imgUrl: '/static/images/vipIcon3.png',
						name: 'بىر تالوندىن 1يۈەن ئايرىلدۇ',
						info: 'جەرىمانە پايدىسى'
					},
					{
						imgUrl: '/static/images/vipIcon4.png',
						name: 'بىر قېتىمدا 0.1يۈەن ئايرىلدۇ',
						info: ' توك پۇلى /تىلفۇن ھەققى '
					}
				],
				price: 0, // 金额
				orderId: '', // 上次支付用的订单id
				orderNo: '' // 上次支付用的订单编号
			};
		},
		
        computed:{
			isVip() {
				return this.userInfo.is_agent === 2
			}
        },
		
		methods: {
			// 后退
			returns() {
				return uni.navigateBack({
					delta: 1,
				})
			},
			// 提交订单
			async toPay() {
				let that = this;
				
				uni.showLoading({
					title: 'تۈلىنۋاتىدۇ'
				});
				let params = {}
				try{
					const resData = await userOpenAgent(params);
					that.payFn(resData);
				}catch(e){
					uni.hideLoading();
				}
			},
			
			// 支付fn
			payFn(resData) {
				let that = this;
				const jsConfig = resData.data.jsConfig;
				const orderInfo = resData.data.order;
				uni.requestPayment({
					timeStamp: jsConfig.timeStamp,
					nonceStr: jsConfig.nonceStr,
					package: jsConfig.package,
					signType: jsConfig.signType,
					paySign: jsConfig.paySign,
					success: function(res) {
						uni.hideLoading();
						that.getUserData();
					},
					fail: function(e) {
						uni.hideLoading();
						if (e.errMsg == 'requestPayment:fail cancel') {
							that.orderId = orderInfo.orderId;
							that.orderNo = orderInfo.orderNo;
							uni.showModal({
								title: that.$i18n['提示'],
								content: that.$i18n['是否取消支付？'],
								cancelText: that.$i18n['确认'],
								confirmText: that.$i18n['取消'],
								success: function (res) {
									if (res.confirm) {
										that.againPay()
									} else if (res.cancel) {
										that.cancelPay()
									}
								}
							});
							return;
						}
					}
				})
			},
			
			// 取消支付
			async cancelPay() {
				uni.showLoading({
					title: ''
				});
				let params = {
					orderId: this.orderId,
					orderNo: this.orderNo
				}
				try{
					const resData = await serOpenPayCancel(params);
					this.$util.Tips({
						title: resData.msg
					})
					uni.hideLoading();
				}catch(e){
					uni.hideLoading();
				}
			},
			
			// 重新支付
			async againPay() {
				uni.showLoading({
					title: 'تۈلىنۋاتىدۇ'
				});
				let params = {
					orderId: this.orderId,
					orderNo: this.orderNo
				}
				try{
					const resData = await userOpenPayAgain(params);
					this.payFn(resData);
				}catch(e){
					uni.hideLoading();
				}
			},
			getUserData() {
				const that = this;
				userAgencyCenter().then(res => {
					that.userInfo = res.data;
				})
			}
		},
		onLoad() {
			this.getUserData()
		}
	}
</script>

<style lang="scss">
	.pageBody {
		width: 750rpx;
		min-height: 100vh;
		background: #46474B;
		background: linear-gradient(180deg, #46474B 0%, #46474B 398rpx, #FFF 400rpx, #FFF 100%);
		.pageHead {
			position: flex;
			.headStatus {
				width: 100%;
			}
			.headNav {
				display: flex;
				height: 43px;
				line-height: 43px;
				text-align: center;
				font-size: 36rpx;
				color: #333;
				.icon-fanhui2 {
					position: absolute;
					left: 40rpx;
					color: #fff;
				}
				.headTitle {
					width: 100%;
					height: 43px;
					line-height: 43px;
					width: 100%;
					text-align: center;
					color: #fff;
				}
			}
		}
		
		
		.bodyWrap {
			padding: 30rpx 0 0;
			overflow-y: auto;
			.cardBox {
				padding-top: 38rpx;
				.vipCard {
					width: 690rpx;
					height: 186rpx;
					background: url(/static/images/vipCard.png);
					margin: 0 auto;
					display: flex;
					padding: 26rpx 44rpx 0;
					background-size: cover;
					.avatar {
						width: 96rpx;
						height: 96rpx;
						border-radius: 50%;
						border: 2rpx solid #FFFFFF;
					}
					.cardInfo {
						padding-left: 24rpx;
						.infoTop {
							display: flex;
							.name {
								font-size: 28rpx;
								font-weight: 500;
								color: #FFFFFF;
								margin-top: 6rpx;
							}
							.ordinaryUser {
								height: 34rpx;
								background-image: url(/static/images/putongyonghu.png);
								background-position: center;
								background-size: 130rpx 34rpx;
								background-repeat: no-repeat;
								padding-left: 40rpx;
								padding-right: 10rpx;
								font-size: 20rpx;
								font-weight: 400;
								color: #F5F7F9;
								margin-left: 10rpx;
								background-color: #a2a8bd;
								border-radius: 40rpx;
								margin-top: 10rpx;
							}
							.vipUser {
								height: 34rpx;
								background-image: url(/static/images/vipyonghu.png);
								background-position: center;
								background-size: 100%;
								background-repeat: no-repeat;
								padding-left: 40rpx;
								padding-right: 10rpx;
								font-size: 20rpx;
								font-weight: 400;
								color: #F5F7F9;
								margin-left: 10rpx;
								background-color: #f4ae5f;
								border-radius: 40rpx;
								margin-top: 10rpx;
							}
						}
						.infoBtm {
							display: flex;
							.infoTime {
								margin-right: 10rpx;
								font-size: 24rpx;
								font-weight: 400;
								color: #FFF4DF;
								margin-top: 14rpx;
							}
						}
					}
				}
				.btmImg {
					width: 750rpx;
					height: 76rpx;
					background-image: url(/static/images/xingzhuang.png);
					background-position: center;
					background-repeat: no-repeat;
					background-size: 100% 100%;
					margin-top: -42rpx;
				}
			}
			.agentBox {
				padding: 0 30rpx;
				background-color: #fff;
				margin-top: -2rpx;
				.agentTitle {
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 32rpx;
					font-weight: 500;
					color: #333333;
					.titleIcon {
						width: 14rpx;
						height: 14rpx;
						background: #DAB77A;
						transform: rotateZ(45deg);
						margin: 0 6rpx;
					}
					.title {
						margin: 0 14rpx;
					}
				}
				.contentBox {
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;
					border-bottom: 2rpx solid #EBEBEB;
					padding-top: 42rpx;
					padding-bottom: 50rpx;
					height: 344rpx;
					align-content: space-between;
					.itemBox {
						width: 50%;
						display: flex;
						.boxImg {
							width: 96rpx;
							height: 96rpx;
							.boxIcon {
								width: 96rpx;
								height: 96rpx;
							}
						}
						.boxInfo {
							padding-left: 26rpx;
							padding-top: 12rpx;
							.boxName {
								min-height: 30rpx;
								line-height: 30rpx;
								font-size: 30rpx;
								font-weight: 500;
								color: #333333;
							}
							.boxContent {
								font-size: 22rpx;
								font-weight: 400;
								color: #999999;
								margin-top: 16rpx;
							}
						}
					}
				}
				.tips {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;
					padding-top: 28rpx;
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 10rpx;
					}
				}
			}
			.btmBox {
				width: 750rpx;
				height: 538rpx;
				.btmBoxWrap {
					width: 750rpx;
					height: 518rpx;
					padding: 50rpx 30rpx 0;
					box-shadow: 0 0 100rpx 0 rgba(179,175,175,0.2000);
					border-radius: 16rpx 16rpx 0rpx 0rpx;
					position: fixed;
					left: 0;
					bottom: 0;
					background-color: #fff;
					.programme {
						width: 688rpx;
						height: 254rpx;
						background: #FFFDF9;
						border-radius: 10rpx;
						border: 2rpx solid #ECDABA;
						text-align: center;
						position: relative;
						padding-top: 48rpx;
						.tips {
							min-width: 148rpx;
							padding: 0 26rpx;
							line-height: 36rpx;
							background: #D8B577;
							border-radius: 20rpx 0rpx 20rpx 0rpx;
							position: absolute;
							left: 0;
							top: -20rpx;
							font-size: 24rpx;
							font-weight: 400;
							color: #FFFFFF;
							text-align: center;
							z-index: 99;
						}
						.dayMoney {
							height: 60rpx;
							font-size: 34rpx;
							font-weight: 400;
							color: #D8B577;
							.text {
								font-size: 26rpx;
								padding: 8rpx;
							}
						}
						.yearMoney {
							height: 36rpx;
							font-size: 26rpx;
							font-weight: 400;
							color: #D8B577;
							margin-top: 20rpx;
						}
						.time {
							width: 100%;
							height: 60rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							background: linear-gradient(90deg, #FEE4A4 0%, #FFDA80 100%);
							position: absolute;
							left: 0;
							bottom: 0;
							font-size: 28rpx;
							font-weight: 400;
							color: #895E26;
						}
					}
					.btmSub {
						display: flex;
						width: 100%;
						height: 140rpx;
						justify-content: space-between;
						.money {
							font-size: 48rpx;
							font-weight: bold;
							color: #333333;
							margin-top: 60rpx;
						}
						.subBtn {
							width: 296rpx;
							height: 96rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							background: linear-gradient(178deg, #FFCE53 0%, #FDD04A 100%);
							border-radius: 50rpx;
							font-size: 32rpx;
							font-weight: 500;
							color: #333333;
							margin-top: 32rpx;
						}
					}
				}
			}
		}
	}
</style>
